package com.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bean.Address;
import com.serve.AddressService;
import com.serveImple.AddressServiceImpl;

/**
 * Servlet implementation class AddressServlet
 */
@WebServlet("/AddressServlet")
public class AddressServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AddressServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		String add_address=request.getParameter("addAddr");
		String add_name=request.getParameter("name");
		String add_phone=request.getParameter("phone");
		System.out.println(add_address);
		System.out.println(add_name);
		System.out.println(add_phone);
		Address address=new Address();
		address.setAdd_name(add_name);
		address.setAddress(add_address);
		address.setAdd_phone(add_phone);
		AddressService addressservice=new AddressServiceImpl();
		int i=addressservice.add(address);
		if(i!=1){
			request.setAttribute("jie", 1);
			request.setAttribute("jieguo", i);
			System.out.println("添加失败");
			request.getRequestDispatcher("easybuy/address2.jsp").forward(request, response);
		}else{
			request.setAttribute("jie", 1);
			request.setAttribute("jieguo", i);
			System.out.println("添加成功");
			request.getRequestDispatcher("AddressShowServlet").forward(request, response);
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request,response);
	}

}
